Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: total ordering for the dependency provider #892

Merged

Conversation

tdejager
Copy link
Collaborator

@tdejager tdejager commented Oct 4, 2024

This should fix the total ordering issues by rewriting how ordering works for the case where the name, version, build number are the same, lets call this set of candidates X.

The old method violated total ordering, with specifically that though a > b, b > c, actually a < c which was incorrect.

The new method compares the set of dependencies that are shared for X. By looking at the shared set of dependencies and devising a matrix that creates a t total order for comparisons, more details are in the code. Tie breaks in this case are done by comparing the timestamp still.

fixes: #888

@tdejager tdejager marked this pull request as ready for review October 4, 2024 14:46
Copy link
Collaborator

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good!

I feel like this would really benefit from a specific test but Im unsure how to do that without too much effort. @wolfv Maybe you have some thoughts?

crates/rattler_conda_types/src/channel/mod.rs Outdated Show resolved Hide resolved
crates/rattler_conda_types/src/version/mod.rs Outdated Show resolved Hide resolved
crates/rattler_conda_types/src/version/mod.rs Outdated Show resolved Hide resolved
crates/rattler_solve/src/resolvo/conda_util.rs Outdated Show resolved Hide resolved
crates/rattler_solve/src/resolvo/conda_util.rs Outdated Show resolved Hide resolved
crates/rattler_solve/src/resolvo/conda_util.rs Outdated Show resolved Hide resolved
crates/rattler_solve/src/resolvo/conda_util.rs Outdated Show resolved Hide resolved
crates/rattler_solve/src/resolvo/conda_util.rs Outdated Show resolved Hide resolved
@wolfv
Copy link
Contributor

wolfv commented Oct 4, 2024

Are there any two packages that would have resulted in a non-total order before? That might make a good test case then?

Co-authored-by: Bas Zalmstra <[email protected]>
@tdejager
Copy link
Collaborator Author

tdejager commented Oct 4, 2024

I could try making traits to get the required fields and make a minimal test like the one wolf suggested. But that would delay the merge a bit. Let me know what you think!

@wolfv
Copy link
Contributor

wolfv commented Oct 4, 2024

It's not possible to make a vector and call sort on it in a test?

@tdejager
Copy link
Collaborator Author

tdejager commented Oct 5, 2024

It's not possible to make a vector and call sort on it in a test?

I think you might think it was one of the trait implementations, which was not the problem. It needs to touch the code in the sorter functions.

Note that the code that was panicking begore is still being run (and not panicking now). This is essentially what you are proposing, albeit not in minimal form.

@tdejager
Copy link
Collaborator Author

tdejager commented Oct 5, 2024

I've made most of the changes, I'm not sure if the added complexity of the traits would be worth it. I could work on that if that is needed in a seperate PR that would not block this change, and the homebrew error. If we can think of an easy integration test to add, I could add that for sure.

cc @wolfv @baszalmstra

Copy link
Collaborator

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments but the docs look great!

crates/rattler_conda_types/src/utils/serde.rs Outdated Show resolved Hide resolved
crates/rattler_conda_types/src/version/mod.rs Outdated Show resolved Hide resolved
crates/rattler_solve/src/resolvo/conda_sorting.rs Outdated Show resolved Hide resolved
crates/rattler_solve/src/resolvo/conda_sorting.rs Outdated Show resolved Hide resolved
@baszalmstra
Copy link
Collaborator

Perhaps we can make a simpler integration test by loading our sample repodata.json, sorting sprcific packages like libuuid and pytorch and creating some snapshots out of that?

@tdejager
Copy link
Collaborator Author

tdejager commented Oct 5, 2024

Perhaps we can make a simpler integration test by loading our sample repodata.json, sorting sprcific packages like libuuid and pytorch and creating some snapshots out of that?

How is that better than the comparison with libsolv that we are currently doing?

@baszalmstra
Copy link
Collaborator

That is testing whether we solve similar which indeed requires sorting but doesnt necessarily hit these edge cases. Besides that I think it would be nice to have a test that highlights how we sort similar packages. Having a snapshot that shows how all pytorch variants are sorted for instance would be quite useful and help guide any future changes.

@baszalmstra
Copy link
Collaborator

One more final thing: Could you also run the rattler_solve benchmarks to see if we didn't accidentally introduce a performance regression?

@tdejager
Copy link
Collaborator Author

tdejager commented Oct 5, 2024

Thanks makes sense will do both. Let me make those test in main first in a separate PR, we can make sure the snapshots stay the same.

@tdejager
Copy link
Collaborator Author

tdejager commented Oct 5, 2024

One more final thing: Could you also run the rattler_solve benchmarks to see if we didn't accidentally introduce a performance regression?

Ok, unfortunately, it seems to decrease performance by quite a margin.
One example(but it's across the board):

old:

solve quetz/resolvo     time:   [187.60 ms 188.11 ms 188.71 ms]

new:

solve quetz/resolvo     time:   [217.02 ms 219.35 ms 221.94 ms]

I improved the perfomance a tiny bit, but I think we need to try and drop most of the HashMap's and work on index-offsets and pre-allocated Vectors with integer slots directly. @baszalmstra wdyt? Can we look at this on monday?

Caching over solves might improve things as well, at least that's what I would reckon.

tdejager added a commit that referenced this pull request Oct 7, 2024
Takes the updated test from #892 and adds sorting bench.
@tdejager tdejager enabled auto-merge (squash) October 7, 2024 14:44
@tdejager tdejager merged commit 6032945 into conda:main Oct 7, 2024
15 checks passed
@baszalmstra baszalmstra mentioned this pull request Oct 7, 2024
@tdejager tdejager deleted the feat/total-order-for-dependency-provider branch October 7, 2024 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Solving panics due to incorrect comparison function
3 participants